<template>
	<div>
		<el-transfer 
		:data="users"
		:props="props"
		v-model="values"
		:titles="titles"
		filterable>	
		</el-transfer>
		<el-button style="margin-top: 20px;" type="primary" plain @click="save">保存</el-button>
	</div>
</template>

<script>
import { get, post } from '@/plugins/axios'
export default {
	name: 'RoleUser',
	created () {
		this.roleId = this.$route.query.roleId
		this.getData()
	},
	data () {
		const module = '/umsRoleUser'
		return {
			roleId: null,
			users: [],
			url: {
				getData: module + '/getData',
				save: module + '/save'
			},
			props: {
				key: 'id',
				label: 'name'
			},
			values: [],
			titles: ['所有用户', '关联用户']
		}
	},
	methods: {
		getData () {
			get(this.url.getData, { roleId: this.roleId }, response => {
				//console.log(response)
				this.users = response.users
				for (const index in response.values) {
					this.values.push(response.values[index].userId)
				}
			})
		},
		save () {
			// console.log(this.values)
			post(this.url.save, {roleId: this.roleId, userIds: this.values}, response => {
				this.$router.push('/role')
			})
		}
	}
}
</script>

<style>
</style>
